package com.cloudspace.jindun.message;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ListView;

import com.android.volley.error.VolleyError;
import com.cloudspace.jindun.R;
import com.cloudspace.jindun.activity.CustomTitleBaseActivity;
import com.cloudspace.jindun.adapter.NoticePersonAdatper;
import com.cloudspace.jindun.model.NoticePersonResult;
import com.cloudspace.jindun.network.api.API;
import com.cloudspace.jindun.network.base.ApiCallback;
import com.cloudspace.jindun.user.UserSessionManager;

/**
 * Created by zengxianhua on 17/3/21.
 */

public class NoticeDetailPageActivity extends CustomTitleBaseActivity{
    private final String TAG = NoticeDetailPageActivity.class.getSimpleName();

    private ListView noticeLv;
    private NoticePersonAdatper noticePersonAdatper;

    private static final String MSG_ID = "MSG_ID";
    private static final String GROUP_ID = "GROUP_ID";

    private String msgId;
    private String groupId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.layout_activity_notice_detail, true);

        getTitleBar().setSimpleMode(getResources().getString(R.string.notice_detail));

        noticePersonAdatper = new NoticePersonAdatper();
        noticeLv = (ListView) findViewById(R.id.notice_lv);
        noticeLv.setAdapter(noticePersonAdatper);

        if (getIntent() != null){
            msgId = getIntent().getStringExtra(MSG_ID);
            groupId = getIntent().getStringExtra(GROUP_ID);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        getNoticeReadStituation();
    }

    private void getNoticeReadStituation(){
        API.getInstance().getNoticeApi().getNoticeReadPerson(TAG,
                msgId, UserSessionManager.getInstance().getUserId(),
                groupId, new ApiCallback<NoticePersonResult>() {
                    @Override
                    public void handleResult(NoticePersonResult result, VolleyError error) {
                        if (result != null && result.status == 200){
                            noticePersonAdatper.setData(result.data);
                        }
                    }
                }.toastActionError()
        );
    }

    public static void showActivity(Context context, InfoMessage infoMessage){
        Intent intent = new Intent(context, NoticeDetailPageActivity.class);

        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(MSG_ID, infoMessage.id);
        intent.putExtra(GROUP_ID, infoMessage.groupId);

        context.startActivity(intent);
    }
}
